import tkinter as tk

# 感知器模型
def nn():
    # 获取所有输入框的值
    values = [float(obj.get()) for obj in objs]
    # 计算总和
    sum = 0
    for i in values:
        sum += i
    # 判断是否去踢足球(阈值：总和大于等于1)
    if sum >= 1:
        result_label.config(text='去踢足球')
    else:
        result_label.config(text='不去踢足球')

# 创建主窗口
root = tk.Tk()
root.title('神经网络（感知器模型）')

# 创建输入框和标签
labels = ['健身', '乐趣', '朋友', '看书', '疲劳']
# 初始化权重
weights = [0.5, 0.8, 0.3, -0.1, 0]
objs = []
# 创建输入框和标签
for i, label in enumerate(labels):
    tk.Label(root, text=label).grid(row=i, column=0)
    obj = tk.Entry(root)
    # 初始化输入框的值
    obj.insert(0, str(weights[i]))
    obj.grid(row=i, column=1)
    objs.append(obj)

# 创建按钮
button = tk.Button(root, text='判断', command=nn)
button.grid(row=len(labels), column=0, columnspan=2)

# 创建结果标签
result_label = tk.Label(root, text='')
result_label.grid(row=len(labels)+1, column=0, columnspan=2)

# 运行主循环
root.mainloop()